package leetcode.code0933;

public class RecentCounter {

	int cnt;

	class Node {
		int val;
		Node next;

		public Node(int val) {
			this.val = val;
		}
	}

	Node L, R;

	public RecentCounter() {
		cnt = 0;
		L = new Node(-1);
		R = L;
	}

	public int ping(int t) {
		R.next = new Node(t);
		R = R.next;
		cnt += 1;
		while (L.next.val < t - 3000) {
			L = L.next;
			cnt -= 1;
		}
		return cnt;
	}
}
